package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/09/01 10:34
 **/
public class Day47_2_Num33_VerifyPostorder {
    class Solution {
        public boolean verifyPostorder(int[] postorder) {
            return judgePost(postorder, 0, postorder.length -1);
        }
        private boolean judgePost(int[] postorder, int left, int right){
            if(left >= right) return true;
            int m = left;
            while(postorder[m] < postorder[right]) m++;
            int p = m;
            while(postorder[p] > postorder[right]) p++;
            return p == right && judgePost(postorder, left, m-1) && judgePost(postorder, m, right-1);
        }
    }
}